home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)view_create.c V1.22 3/13/95";
- #endif
- /*
- | file name - view_create.c
- |
- |===================================================================
- |
- | This program demonstrates the basics of creating the entire
- | structure of a view entirely within a DV-Tools' program.
- | Nothing is pre-created or pre-loaded from DV-Draw into this
- | program. Three basic types of objects are created:
- |
- | (1) object with dynamic colors
- | (2) subdrawing with subdrawing dynamics
- | (3) a line graph
- |
- | To run this program, type:
- |
- | view_create
- |
- | The resulting view is written to the file "created.view". Use
- | DV-Draw or DV-Play to display the newly created view.
- |
- | In the case of the subdrawing dynamics, it should be noted that
- | the threshold table CANNOT be edited, because the subdrawings'
- | views were never saved to files.
- |
- |===================================================================
- */
- #include <windows.h>
-
- #include "std.h" /* include <stdio.h> plus some */
- #include "dvstd.h" /* DV standard definitions (internals) */
- #include "dvtools.h" /* DV-Tools definitions (visible) */
- #include "VOstd.h" /* DV-Tools object definitions */
- #include "dvfuns.h" /* DV-Tools function declarations */
- #include "Tfundecl.h" /* DV-Tools T function declarations */
- #include "VOfundecl.h" /* DV-Tools VO function declarations */
-
- static char srcfile[]= "default.dat";
- static char viewfile[]= "created.view";
-
- /* Functions defined in view_create.c */
- DSVAR SetDataSourceList V_P_((VIEW view));
- void MakeDynamicColorObject V_P_((OBJECT drawing, DSVAR dsv));
- void MakeDynamicSubdrawing V_P_((OBJECT drawing, DSVAR dsv));
- void CreateSubdrawings V_P_((OBJECT anchorpt, OBJECT *circsd_p,
- OBJECT *rectsd_p, OBJECT *linesd_p));
- void MakeGraph V_P_((OBJECT drawing, DSVAR dsv));
-
- /* =========================================>>> MAIN PROGRAM ... */
-
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- VIEW view;
- DSVAR dsv;
- OBJECT drawing;
- int argc;
- char **argv;
- char mes_str[100];
-
- make_argv(&argc,&argv,GetCommandLine());
- /* Initialize DVtools - use DVPATH config variable for path */
- TInit ((char *) NULL, (char *) NULL);
-
- /* Create an empty view */
- view = TviCreate ();
-
- /* Create data source list - get back one controlling data source var */
- dsv = SetDataSourceList (view);
-
- /* Create empty drawing */
- drawing = TviGetDrawing (view);
-
- /* Create an object with color dynamics */
- MakeDynamicColorObject (drawing, dsv);
-
- /* Create a subdrawing with subdrawing dynamics */
- MakeDynamicSubdrawing (drawing, dsv);
-
- /* Create a graph */
- MakeGraph (drawing, dsv);
-
- /* Save the new view */
- TviSave (view, viewfile);
-
- /* Exit DVtools */
- TTerminate ();
-
- /* Print success message and exit */
- sprintf( mes_str, "File 'created.view' created.\n" );
- strcat( mes_str,"Use DV-Draw or DV-Play to display.\n" );
- MessageBox (
- GetFocus (),
- mes_str,
- "view_create:",
- MB_OK
- );
-
- return EXIT_OK;
- }
-
-
- /* =========================================>>> CREATES DATASOURCELIST ... */
- /* Set the data source list with a newly created data source */
-
- DSVAR
- SetDataSourceList (view)
- VIEW view;
- {
- DATASOURCE ds;
- DATASOURCELIST ds_list;
- DSVAR dsv;
-
- /* Create an empty data source list */
- ds_list = TviGetDataSourceList (view);
-
- /* Create empty data source */
- ds = TdsCreate ();
-
- /* Define data source's source */
- TdsEditAttributes (ds, DSFILE, DSASCII, srcfile);
-
- /* Create data source variable and set its attributes */
- dsv = TdsvCreate ();
- TdsvEditAttributes (dsv, "Input_Var", V_F_TYPE, 1, 1, (int) NULL);
-
- /* Attach ds var to data source */
- TdsAddDsVar (ds, dsv, (ADDRESS) NULL);
-
- /* Attach data source to ds list */
- TdlAddDataSource (ds_list, ds, (DATASOURCE) NULL);
-
- /* Return back the one controlling data source variable */
- return dsv;
- }
-
-
- /* ==============================>>> CREATES OBJECT WITH DYNAMIC COLOR... */
- /* Makes a graphical object with dynamic color control */
-
- void
- MakeDynamicColorObject (drawing, dsv)
- OBJECT drawing;
- DSVAR dsv;
- {
- OBJECT circle, dyn_control, default_color, color_tt;
- OBJECT center, radius, vd;
-
- /* Create an ordinary circle */
- center = VOptCreate (WORLD_COORDINATES, -10000, 4000, (OBJECT) NULL);
- radius = VOptCreate (WORLD_COORDINATES, -9000, 5000, (OBJECT) NULL);
- circle = VOciCreate (center, radius, (ATTRIBUTES *) NULL);
-
- /* Attach circle to drawing */
- VOdrObAdd (drawing, circle);
-
- /* Create vd object to control threshold table */
- vd = VOvdCreate (dsv, NUMBER, (DATUM) 0.0);
-
- /* Set the vdp active range */
- VPvd_drange (VOvdGetVdp (vd), 0.0, 1.0);
-
- /* Create a threshold table and default for color change */
- default_color = VOcoCreate (COLOR_COMPONENTS, 255, 0, 122);
- color_tt = VOttCreate (vd, OBJECT_DATUM (OT_COLOR), default_color);
-
- /* Add the thresholds to the table - values must be normalized */
- VOttAddThresh (color_tt, 1 * 32767 / 5, VOcoCreate (COLOR_COMPONENTS, 255, 0, 0));
- VOttAddThresh (color_tt, 2 * 32767 / 5, VOcoCreate (COLOR_COMPONENTS, 255, 255, 0));
- VOttAddThresh (color_tt, 3 * 32767 / 5, VOcoCreate (COLOR_COMPONENTS, 255, 255, 255));
- VOttAddThresh (color_tt, 4 * 32767 / 5, VOcoCreate (COLOR_COMPONENTS, 0, 255, 255));
- VOttAddThresh (color_tt, 32767, VOcoCreate (COLOR_COMPONENTS, 0, 0, 255));
-
- /* Create a dynamic control object and set the erase method */
- dyn_control = VOdyCreate ();
- VOdySetEraseMethod (dyn_control, V_DYN_ERASE_BGCLR);
-
- /* Attach the threshold table to the dynamic control object */
- VOdyAttachData (dyn_control, FOREGROUND_COLOR, color_tt,
- (float *) NULL, (float *) NULL, (OBJECT) NULL,
- (OBJECT) NULL);
-
- /* Attach the dynamic control object to the circle */
- VOobDySet (circle, dyn_control);
- }
-
-
- /* ====================================>>> CREATES DYNAMIC SUBDRAWING ... */
- /* Make a subdrawing with special subdrawing dynamics */
-
- void
- MakeDynamicSubdrawing (drawing, dsv)
- OBJECT drawing;
- DSVAR dsv;
- {
- OBJECT vd, anchorpt, subdraw_tt, dyn_control;
- OBJECT topsd, rectsd, linesd, circsd;
-
- /* Create vd object to control threshold table */
- vd = VOvdCreate (dsv, NUMBER, (DATUM) 0.0);
-
- /* Set the vdp active range */
- VPvd_drange (VOvdGetVdp (vd), 0.0, 1.0);
-
- /* Create an anchor point for subdrawings */
- anchorpt = VOptCreate (WORLD_COORDINATES, 10000, 4000, (OBJECT) NULL);
-
- /* Call function to create three different subdrawings */
- CreateSubdrawings (anchorpt, &circsd, &rectsd, &linesd);
-
- /* Create a top-level subdrawing - a clone of one of the subdrawings */
- topsd = VOobClone (circsd);
-
- /* Add the top-level subdrawing directly to the drawing */
- VOdrObAdd (drawing, topsd);
-
- /* Create a threshold table for subdrawing change - use circle for default */
- subdraw_tt = VOttCreate (vd, OBJECT_DATUM (OT_SUBDRAWING), circsd);
-
- /* Add the subdrawings to the table - threshold values must be normalized */
- VOttAddThresh (subdraw_tt, 1 * 32767 / 3, rectsd);
- VOttAddThresh (subdraw_tt, 2 * 32767 / 3, linesd);
-
- /* Create a dynamic control object and set the erase method */
- dyn_control = VOdyCreate ();
- VOdySetEraseMethod (dyn_control, V_DYN_ERASE_BGCLR);
-
- /* Attach the threshold table to the dynamic control object */
- VOdyAttachData (dyn_control, V_DYN_SUBDRAWING, subdraw_tt,
- (float *) NULL, (float *) NULL, (OBJECT) NULL,
- (OBJECT) NULL);
-
- /* Attach the dynamic control object to the top-level subdrawing */
- VOobDySet (topsd, dyn_control);
- }
-
-
- void
- CreateSubdrawings (anchorpt, circsd_p, rectsd_p, linesd_p)
- OBJECT anchorpt;
- OBJECT *circsd_p;
- OBJECT *rectsd_p;
- OBJECT *linesd_p;
- {
- VIEW sd_view1, sd_view2, sd_view3;
- OBJECT sd_drawing, circle, rect, line;
- OBJECT center, radius, point1, point2;
-
- /* Create a circle */
- center = VOptCreate (WORLD_COORDINATES, 0, 0, (OBJECT) NULL);
- radius = VOptCreate (WORLD_COORDINATES, 1000, 1000, (OBJECT) NULL);
- circle = VOciCreate (center, radius, (ATTRIBUTES *) NULL);
-
- /* Create a circle subdrawing */
- sd_view1 = TviCreate ();
- sd_drawing = TviGetDrawing (sd_view1);
- VOdrObAdd (sd_drawing, circle);
- *circsd_p = VOsdCreate ((char *) NULL, sd_view1, anchorpt, 1.0,
- (ATTRIBUTES *) NULL);
-
- /* Create a rectangle */
- point1 = VOptCreate (WORLD_COORDINATES, -1000, -1000, (OBJECT) NULL);
- point2 = VOptCreate (WORLD_COORDINATES, 1000, 1000, (OBJECT) NULL);
- rect = VOreCreate (point1, point2, (ATTRIBUTES *) NULL);
-
- /* Create a rectangle subdrawing */
- sd_view2 = TviCreate ();
- sd_drawing = TviGetDrawing (sd_view2);
- VOdrObAdd (sd_drawing, rect);
- *rectsd_p = VOsdCreate ((char *) NULL, sd_view2, anchorpt, 1.0,
- (ATTRIBUTES *) NULL);
-
- /* Create a line */
- point1 = VOptCreate (WORLD_COORDINATES, -1000, -1000, (OBJECT) NULL);
- point2 = VOptCreate (WORLD_COORDINATES, 1000, 1000, (OBJECT) NULL);
- line = VOlnCreate (point1, point2, (ATTRIBUTES *) NULL);
-
- /* Create a line subdrawing */
- sd_view3 = TviCreate ();
- sd_drawing = TviGetDrawing (sd_view3);
- VOdrObAdd (sd_drawing, line);
- *linesd_p = VOsdCreate ((char *) NULL, sd_view3, anchorpt, 1.0,
- (ATTRIBUTES *) NULL);
- }
-
-
- /* =========================================>>> CREATES GRAPH ... */
- /* Create a line graph */
-
- GLOBALREF DISPFORM VDline;
-
- void
- MakeGraph (drawing, dsv)
- OBJECT drawing;
- DSVAR dsv;
- {
- OBJECT linegraph, ll, ur;
- float start = 1.0, incr = 1.0;
- DATAGROUP dgp;
- VARDESC vdp;
- float FloatVar = 0.0;
-
- /* Create the variable descriptor pointer with a base address
- defined by FloatVar and the variable descriptor data type
- is defined to be Float. */
- vdp = VPvdcreate ((ADDRESS) & FloatVar, V_F_TYPE);
-
- /* Attach the vdp to the passed data source variable. This call
- will change the access mode of the variable from direct to
- data source bound. The variable will now point to the data
- source variable instead of the address location of FloatVar. */
- TvdPutDataSourceVariable (vdp, dsv);
-
- /* Set the vdp active range */
- VPvd_drange (vdp, 0.0, 1.0);
-
- /* Create linegraph object */
- ll = VOptCreate (WORLD_COORDINATES, -10000, -10000, (OBJECT) NULL);
- ur = VOptCreate (WORLD_COORDINATES, 2000, -1000, (OBJECT) NULL);
- linegraph = VOdgCreate ((ADDRESS) NULL, ll, ur, (ATTRIBUTES *) NULL);
-
- /* Get data group structure */
- dgp = (DATAGROUP) VOdgGetDgp (linegraph);
-
- /* Attach line graph data format, display and label tic marks */
- VPdgdf (dgp, VDline);
- VPdgcontext (dgp, (LONG) V_FT_TICS | V_FV_TICS | V_FT_LABEL_TICS |
- V_FV_LABEL_TICS, YES);
-
- /* Set range of time axis, set start time and increment, set scroll amount */
- VPdgslots (dgp, 10);
- VPdgtime_start_incr (dgp, &start, &incr);
- VPdgscroll_amount (dgp, 0);
-
- /* Attach dgp to vdp, label time axis, vertical axis, and graph title */
- VPdgvdswitch (dgp, 1, vdp);
- VPdgaxlabel (dgp, V_TIME_AXIS, "Time");
- VPvdvallabel (vdp, "Value");
- VPdgtitle (dgp, "Example of Graph Dynamics");
-
- /* Attach the graph to the drawing */
- VOdrObAdd (drawing, linegraph);
- }
-
- /* ---------------------------------------->>> END OF PROGRAM <<< */
-